package com.ymtms.arrivalofgoods.controller;

import com.ymtms.arrivalofgoods.aspect.ArriveAspect;
import com.ymtms.arrivalofgoods.exception.CheckException;
import com.ymtms.arrivalofgoods.service.CheckGoodsCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.thymeleaf.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

@Controller
@CrossOrigin
public class CheckCustomerController {
    @Autowired
    private CheckGoodsCustomerService checkGoodsCustomerService;


    @ResponseBody
    @RequestMapping("/checkCustomer")
    public Map checkReceiveGoods(Integer num) {
        Map map = new HashMap();
        if (StringUtils.isEmpty(num.toString())) {
            map.put("code", "500");
            map.put("msg", "请先选择");
            return map;
        }

        try {
            checkGoodsCustomerService.modifyStatusByNum(num);
            checkGoodsCustomerService.insertReceiptHistory(num);
            map.put("code", "0");
            map.put("msg", "success");
        } catch (CheckException e) {
            map.put("code", "500");
            map.put("msg", e.getMessage());
           // System.out.println(e.getMessage());
           // e.printStackTrace();
        }
        return map;

    }


}
